package com.example.aigc_education.controller;

//import com.agentsflex.agent.LLMAgent;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.aigc_education.domain.Question;
import com.example.aigc_education.domain.vo.QuestionAnalysisVO;
import com.example.aigc_education.prompt.ProduceQuestionPrompts;
import com.example.aigc_education.service.QuestionService;
import com.example.aigc_education.utils.ResultUtil;
import com.example.aigc_education.utils.SecurityUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

// import static com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation.ANONYMOUS.required;

/**
 * 试题控制器类，负责处理试题相关的HTTP请求。
 */
@RequestMapping("/question")
@RestController
public class QuestionController {

    @Resource
    private QuestionService questionService;


    /**
     * 获取所有试题（待测试）
     * @param composeFlag 组卷标志
     * @return 返回所有试题 or 可以组卷试题
     */
    @GetMapping("/all")
    public ResultUtil getAllQuestions(@RequestParam(required = false)int composeFlag
                                      ) {
        if (composeFlag == 1 ) {
            List<Question> questionList = questionService.list(new LambdaQueryWrapper<Question>()
                .eq(Question::getComposeFlag, composeFlag)
                );
            return ResultUtil.success(questionList);
        }
        List<Question> questionList = questionService.list();
        return ResultUtil.success(questionList);
    }


    /**
     * 获取用户创建的试题
     * @return 返回用户的试题
     */
    @GetMapping("/byUser")
    public ResultUtil getQuestionsByUser() {
        Long userId = SecurityUtils.getUserId();
        List<Question> questionList = questionService.list(new LambdaQueryWrapper<Question>().eq(Question::getCreateBy, userId));
        return ResultUtil.success(questionList);
    }


    /**
     * 同步做法
     * 添加试题
     * @param grade 年级
     * @param textbook 教材
     * @param questionType 试题类型
     * @param questionNum 试题数量
     * @param difficulty 难度
     * @param unitName 单元名称
     * @param unitContent 单元内容
     * @param scene 情景
     * @return 返回生成的试题数量
     */
    @PostMapping("/add")
    public ResultUtil addQuestion(@RequestParam String grade,
                                  @RequestParam String textbook,
                                  @RequestParam String questionType,
                                  @RequestParam int questionNum,
                                  @RequestParam String difficulty,
                                  @RequestParam String unitName,
                                  @RequestParam String unitContent,
                                  @RequestParam(required = false) String scene) {
        List<Question> res = questionService.generateQuestionList( textbook, questionType, questionNum, difficulty, unitName, unitContent, scene);

        return ResultUtil.success("生成题目成功", res);
    }


    /**
     * 单个题目进行ai错题分析（或批量题目进行ai错题分析）
     * @param questionJson 答题情况的json格式，包含题目内容、用户答案、正确答案、知识点
     * @return
     */
    @PostMapping("/analysis")
    public ResultUtil getOneErrorQuestionAnalysis(String questionJson){
        QuestionAnalysisVO questionAnalysis = questionService.getQuestionAnalysis(questionJson);
        return ResultUtil.success(questionAnalysis);
    }

//    /**
//     * 批量题目进行ai错题分析
//     * @param questionListJson 多题目答题情况的json格式
//     * @return
//     */
//    @PostMapping("/analysis")
//    public ResultUtil getListErrorQuestionAnalysis(String questionListJson){
//        return null;
//    }


}
